﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

namespace Eugenhome.Atrium.Bookmark
{
    /// <summary>
    /// 
    /// </summary>
    public class Bookmark
    {
        /// <summary></summary>
        [XmlIgnore]
        internal BookmarkCollection _parentCollection;

        /// <summary></summary>
        public int ID { get; set; }
        /// <summary></summary>
        public int Sort { get; set; }
        /// <summary></summary>
        public string DisplayName { get; set; }
        /// <summary></summary>
        public string Href { get; set; }
        /// <summary></summary>
        public string LabelsString { get; set; }
        /// <summary></summary>
        public bool OpenInNewWindow { get; set; }
        /// <summary></summary>
        public bool Crypted { get; set; }
        /// <summary></summary>
        public string Icon { get; set; }
        /// <summary></summary>
        public string DisplayInternName { get { return string.Format("{0}: {1}", Sort, DisplayName); } }

        /// <summary></summary>
        [XmlIgnore]
        public List<string> Labels { get { return LabelsString.Split(new string[] { BookmarkCollection.LABEL_SPLITTER }, StringSplitOptions.RemoveEmptyEntries).ToList(); } }

        /// <summary>
        /// 
        /// </summary>
        public Bookmark()
        {
            ID = -1;
            Sort = 0;
            OpenInNewWindow = true;
            Crypted = false;
        }

        /// <summary>
        /// 
        /// </summary>
        public void Update()
        {
            _parentCollection.Save();
            _parentCollection.Load();
        }

        /// <summary>
        /// 
        /// </summary>
        public void Delete()
        {
            _parentCollection.Delete(this);
        }
    }
}
